home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / mcdstd.h < prev    next >
C/C++ Source or Header  |  1999-03-06  |  31KB  |  591 lines

  1. /*  MCDstd.h
  2.  
  3.   matrix management functions:
  4.   manipulations on matrices of data type "dComplex"
  5.   (double-precision complex numbers)
  6.  
  7.   Copyright (c) 1996-1999 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #if !defined( __MATLIB_H )
  12.    #include <MatLib.h>
  13. #endif
  14. #if !defined( __VCDSTD_H )
  15.    #include <VCDstd.h>
  16. #endif
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. /*************   Dynamic Generation of Matrices   ************************/
  23.  
  24. cdMatrix __vf  MCD_matrix(  unsigned ht, unsigned len );
  25. cdMatrix __vf  MCD_matrix0( unsigned ht, unsigned len );
  26.     /*  notice that, in the memory model HUGE,
  27.         neither len nor ht may exceed 2047                */
  28.  
  29. /***************************************************************************
  30.  *  The following definitions ensure compatibility between dynamically     *
  31.  *  and statically allocated matrices. The definitions are somewhat        *
  32.  *  cumbersome, but the result for you is that you need not care about     *
  33.  *  the differences between the two types.                                 *
  34.  *  (Internally, the address of the first element of any matrix is needed; *
  35.  *  the expression "MA[0]" is evaluated in a different way for both types, *
  36.  *  but yields in either case the correct address to be passed to the      *
  37.  *  function you wish to call.)                                            *
  38.  *  Only in the rare case that you need to pass the address of one of      *
  39.  *  these functions as an argument to another function, you have to use    *
  40.  *  the actual run-time functions defined further below. Be careful with   *
  41.  *  this: future development of compilers may allow us to avoid this un-   *
  42.  *  handy scheme of macros. So future versions of MatrixLib may no longer  *
  43.  *  use these run-time names.                                              *
  44.  ***************************************************************************/
  45.  
  46.  
  47. /***  Addressing single elements of dynamically allocated matrices: ******
  48.      These two functions are for compatibility with Pascal
  49.      (where elements of dynamically allocated matrices are not directly
  50.      accessible), and for getting around the pointer arithmetics bug in
  51.      some versions of Borland C++.                                     */
  52.  
  53. #define MCD_Pelement( MA, ht, len, m, n ) MCDPelement( MA[0], ht, len, m, n )
  54.                      /* returns a pointer to MA[m][n]. */
  55. #define MCD_element( MA, ht, len, m, n ) *MCDPelement( MA[0], ht, len, m, n )
  56.                      /* dereferenced pointer */
  57.  
  58.  /****************  Initialization  ***************************************
  59.  
  60.     To initialize all elements of a matrix with the same value,
  61.     or to perform arithmetic operations on all elements simultaneously,
  62.     refer to the functions of VectorLib, declared in <VCDstd.h>, <VCDmath.h>.
  63.     In order to use the VectorLib functions, utilize the feature that
  64.     the whole matrix occupies one contiguous area in memory: pass the
  65.     address of the first row to the desired vector function, the size
  66.     of the "vector" being len * ht.
  67.     For example, initialize all elements of the matrix MA with {1.0, 0.0}
  68.     (this is *NOT* the identity matrix)  by calling
  69.         VCD_equ1( MA[0], len * ht );
  70. */
  71.  
  72. #define MCD_equ1( MA, len )                MCDequ1( MA[0], len )
  73.                        /* this is the identity matrix */
  74. #define MCD_outerprod( MA, X, Y, ht, len ) MCDouterprod( MA[0], X, Y, ht, len )
  75.                        /* sizX=ht, sizY=len */
  76. #define MCD_Row_equC( MA, ht, len, iRow, C ) \
  77.                                         MCDRow_equC( MA[0], ht, len, iRow, C )
  78. #define MCD_Col_equC( MA, ht, len, iCol, C ) \
  79.                                         MCDCol_equC( MA[0], ht, len, iCol, C )
  80. #define MCD_Dia_equC( MA, len, C )       MCDDia_equC( MA[0], len, C )
  81.  
  82. #define MCD_Row_equV( MA, ht, len, iRow, X ) \
  83.                                         MCDRow_equV( MA[0], ht, len, iRow, X )
  84. #define MCD_Col_equV( MA, ht, len, iCol, X ) \
  85.                                         MCDCol_equV( MA[0], ht, len, iCol, X )
  86. #define MCD_Dia_equV( MA, len, X )      MCDDia_equV( MA[0], len, X )
  87.  
  88. #define MCD_equM( MB, MA, ht, len )  VCD_equV( MB[0], MA[0], ((ui)(len))*(ht) )
  89.  
  90. #define MCD_UequL( MA, len ) MCDUequL( MA[0], len )
  91. #define MCD_LequU( MA, len ) MCDLequU( MA[0], len )
  92.          /* copy lower-diagonal elements into upper-diagonal
  93.            (or vice versa) by index-reflection, so as to
  94.            get a symmetric matrix    */
  95.  
  96.             /* data-type conversions:  */
  97. #define M_CDtoCF( MCF, MCD, ht, len ) V_CDtoCF( MCF[0], MCD[0], ((ui)ht)*len )
  98. #define M_CFtoCD( MCD, MCF, ht, len ) V_CFtoCD( MCD[0], MCF[0], ((ui)ht)*len )
  99. #define M_CEtoCD( MCD, MCE, ht, len ) V_CEtoCD( MCD[0], MCE[0], ((ui)ht)*len )
  100. #define M_CDtoCE( MCE, MCD, ht, len ) V_CDtoCE( MCE[0], MCD[0], ((ui)ht)*len )
  101.  
  102. /********  Extracting a submatrix and copying a submatrix back  *********/
  103.  
  104. #define MCD_submatrix( MSub, subHt, subLen, \
  105.                        MSrce, srceHt, srceLen, \
  106.                        firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
  107.                MCDsubmatrix(  MSub[0], subHt, subLen, \
  108.                               MSrce[0], srceHt, srceLen, \
  109.                               firstRowInCol, sampInCol, firstColInRow, sampInRow )
  110.  
  111. #define MCD_submatrix_equM( MDest, destHt, destLen, \
  112.                             firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  113.                             MSrce, srceHt, srceLen ) \
  114.                MCDsubmatrix_equM(  MDest[0], destHt, destLen, \
  115.                              firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  116.                              MSrce[0], srceHt, srceLen )
  117.  
  118. /*****   Extracting a single row or a single column or the diagonal  ******
  119.  *       and storing it into a vector                                     */
  120.  
  121. #define MCD_Row_extract( Y, MA, ht, len, iRow ) \
  122.                                      MCDRow_extract( Y, MA[0], ht, len, iRow )
  123. #define MCD_Col_extract( Y, MA, ht, len, iCol ) \
  124.                                      MCDCol_extract( Y, MA[0], ht, len, iCol )
  125. #define MCD_Dia_extract( Y, MA, len ) MCDDia_extract( Y, MA[0], len )
  126.  
  127.  
  128. /*****************    Basic arithmetic operations *********************
  129.                       performed on one single row,
  130.                       or one single column of any matrix,
  131.                       or on the diagonal of a square matrix
  132.  
  133.     Note: In contrast to the analogous VectorLib functions, the operations
  134.     are performed in-place, i.e. the input matrix itself is changed  */
  135.  
  136. #define MCD_Row_addC( MA, ht, len, iRow, C ) \
  137.                                      MCDRow_addC( MA[0], ht, len, iRow, C )
  138. #define MCD_Col_addC( MA, ht, len, iCol, C ) \
  139.                                      MCDCol_addC( MA[0], ht, len, iCol, C )
  140. #define MCD_Dia_addC( MA, len, C )   MCDDia_addC( MA[0], len, C )
  141.  
  142. #define MCD_Row_addV( MA, ht, len, iRow, X ) \
  143.                                      MCDRow_addV( MA[0], ht, len, iRow, X )
  144. #define MCD_Col_addV( MA, ht, len, iCol, X ) \
  145.                                      MCDCol_addV( MA[0], ht, len, iCol, X )
  146. #define MCD_Dia_addV( MA, len, X )   MCDDia_addV( MA[0], len, X )
  147.  
  148. #define MCD_Row_subC( MA, ht, len, iRow, C ) \
  149.                                      MCDRow_addC( MA[0], ht, len, iRow, (-C) )
  150. #define MCD_Col_subC( MA, ht, len, iCol, C ) \
  151.                                      MCDCol_addC( MA[0], ht, len, iCol, (-C) )
  152. #define MCD_Dia_subC( MA, len, C )   MCDDia_addC( MA[0], len, (-C) )
  153.  
  154. #define MCD_Row_subV( MA, ht, len, iRow, X ) \
  155.                                      MCDRow_subV( MA[0], ht, len, iRow, X )
  156. #define MCD_Col_subV( MA, ht, len, iCol, X ) \
  157.                                      MCDCol_subV( MA[0], ht, len, iCol, X )
  158. #define MCD_Dia_subV( MA, len, X )   MCDDia_subV( MA[0], len, X )
  159.  
  160. #define MCD_Row_subrC( MA, ht, len, iRow, C ) \
  161.                                      MCDRow_subrC( MA[0], ht, len, iRow, C )
  162. #define MCD_Col_subrC( MA, ht, len, iCol, C ) \
  163.                                      MCDCol_subrC( MA[0], ht, len,